using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using MemberMgr.Data.ManagerObjects;
using MemberMgr.Data.BusinessObjects;
using MemberMgr.Data.Base;

namespace MemberMgr.Data.UnitTests
{
	[TestFixture]
    public partial class tRightTests : UNuitTestBase
    {
        protected ItRightManager manager;
		
		public tRightTests()
        {
            manager = managerFactory.GettRightManager();
        }
		
		protected tRight CreateNewtRight()
		{
			tRight entity = new tRight();
			
			
			entity.Righttype = "T";
			entity.Rightno = "Test Test ";
			
			ItRoleManager tRoleManager = managerFactory.GettRoleManager();
			entity.TRole = tRoleManager.GetAll(1)[0];
			
			return entity;
		}
		protected tRight GetFirsttRight()
        {
            IList<tRight> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				tRight entity = CreateNewtRight();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                tRight entityA = CreateNewtRight();
				manager.Save(entityA);

                tRight entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                tRight entityA = GetFirsttRight();
				
				entityA.Righttype = "Te";
				
				manager.Update(entityA);

                tRight entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Righttype, entityB.Righttype);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                tRight entity = GetFirsttRight();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

